Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

229
Vistas
ajax request on project 1 call project 2 symfony return Unexpected token <

I have 2 projects, let's call them backend and frontend. Backend is a Symfony3 project and Frontend is a simple html page with javascript in it.

I would like to call a peculiar url of the backend from the frontend so that it would return a string (a url).

So what I tried to do is a simple ajax get request with the backend url I would like to request but this returns

SyntaxError: Unexpected token "<"

(for html dataType) and

SyntaxError: Unexpected token.

(for json and jsonp dataType).

I tried with dataType json, jsonp, html adapting each time the controller response to answer respectively json, json, and html.

When I try this request from postman everything works just fine and i get either my json or html.

There is obviously something I don't understand.

Is there anybody that could explain me what I do wrong and how I could do it.

Below is my frontend project ajax request (for html in that case but I've let the commented json part I've jused for test in case of...)

$.ajax({
                url: 'http://sevignemiroir.local/display',
                type: 'GET',
                dataType:  "html",
                //dataType: "jsonp"
                success: function(response) {
                    console.log('success');
                    console.log(response);
                },
                error: function (response) {
                    console.log('error');
                    console.log(response);
                }
            })

And this my response from my backend symfony controller

public function indexAction()
{
    //return $this->json('toto');
    return $this->render('display/test.html.twig', [
        'toto' => 'toto'
    ]);
}

the test.html.twig file :

<div>test</div>

I am a bit confused :

  • Do I have to apply a specific format to the response to make it work?
  • Is there something I should configure in my controller to allow request from outside the project?
  • Does the problem come from a Cross-Domain issue?
  • I've heard about FOSRestBundle, is it mandatory to use such bundle to enable data send from outside the project?
  • What are the best practices for calling data from a project to another project?

These are the questions I'm getting confused with and if anyone would be kind enough to explain it, that would be greatly appreciated!

I don't know if that's important but I'm using MAMP and both project have virtualhosts configured

Many thanks to those that will take time to read this :)

about 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

It now works but... I don't know why. I was installing various bundle on symfony (FOSRest, NelmioCors, JMS) and tried a jquery cross-plugin plugins, nohing was working but when I removed al of them, it now worked.. :/

about 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda